package com.yeeverse.sdk.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 序列号生成
 *
 * @author sinhoo
 */
public class TraceIdGenerate {

    private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyMMddHHmmssSSS");

    private static String fillZero(String ori, long length) {
        if ((long) ori.length() == length) {
            return ori;
        } else {
            StringBuilder sb = new StringBuilder();

            for (int i = ori.length(); (long) i < length; ++i) {
                sb.append(0);
            }

            sb.append(ori);
            return sb.toString();
        }
    }

    /**
     * 生成订单号
     *
     * @return
     */
    public static String generteNo() {
        int randomNum = (int) (Math.random() * 1000.0D);
        String randomNumStr = fillZero(String.valueOf(randomNum), 3L);
        String orderNo = DATE_FORMAT.format(new Date()) + randomNumStr;
        return orderNo;
    }

}
